﻿<UserControl x:Class="F5.BigIp.LocalTrafficManager.UI.Views.PoolMemberControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:local="clr-namespace:F5.BigIp.LocalTrafficManager.UI.ViewModels"
             mc:Ignorable="d"
             d:DesignHeight="300" 
             d:DesignWidth="300">

    <UserControl.DataContext>
        <local:MainViewModel />
    </UserControl.DataContext>

    <DataGrid x:Name="DataGrid" 
              ItemsSource="{Binding PoolMembers}"
              IsReadOnly="True" 
              AutoGenerateColumns="False"
              GridLinesVisibility="Vertical"
              RowHeaderWidth="0" >

        <i:Interaction.Triggers>
            <i:EventTrigger EventName="SelectionChanged">
                <i:InvokeCommandAction Command="{Binding PoolMemberSelectionChanged}" 
                                       CommandParameter="{Binding SelectedItems, ElementName=DataGrid}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>

        <DataGrid.Resources>

            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="{x:Static SystemColors.InactiveCaptionColor}"/>

            <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
                <Setter Property="Height" Value="32" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type DataGridCell}">
                            <Grid Background="{TemplateBinding Background}">
                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="LeftAlignedCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type DataGridCell}">
                            <Grid Background="{TemplateBinding Background}">
                                <ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Center" Margin="4,0,4,0" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="StatusCellStyle" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=Status}" Value="Enabled">
                        <Setter Property="Background" Value="DarkGreen" />
                        <Setter Property="Foreground" Value="White" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=Status}" Value="Disabled">
                        <Setter Property="Background" Value="DarkRed" />
                        <Setter Property="Foreground" Value="White" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=Status}" Value="Offline">
                        <Setter Property="Background" Value="DimGray" />
                        <Setter Property="Foreground" Value="White" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style TargetType="Image">
                <Setter Property="Width" Value="16"/>
                <Setter Property="Height" Value="16"/>
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Opacity" Value="0.2" />
                    </Trigger>
                </Style.Triggers>
            </Style>

        </DataGrid.Resources>

        <DataGrid.ContextMenu>
            <ContextMenu>
                <MenuItem Header="Enable" 
                          ToolTip="All traffic allowed"
                          CommandParameter="{Binding SelectedPoolMembers}" 
                          Command="{Binding EnableCommand}" >
                    <MenuItem.Icon>
                        <Image Source="/F5.BigIp.LocalTrafficManager.UI;component/Resources/play.png"/>
                    </MenuItem.Icon>
                </MenuItem>

                <MenuItem Header="Disable"
                          ToolTip="Only persistent or active connections allowed"
                          CommandParameter="{Binding SelectedPoolMembers}" 
                          Command="{Binding DisableCommand}">
                    <MenuItem.Icon>
                        <Image Source="/F5.BigIp.LocalTrafficManager.UI;component/Resources/pause.png"/>
                    </MenuItem.Icon>
                </MenuItem>

                <MenuItem Header="Force Offline"
                          ToolTip="Only active connections allowed"
                          CommandParameter="{Binding SelectedPoolMembers}" 
                          Command="{Binding ForceOfflineCommand}">
                    <MenuItem.Icon>
                        <Image Source="/F5.BigIp.LocalTrafficManager.UI;component/Resources/stop.png"/>
                    </MenuItem.Icon>
                </MenuItem>

            </ContextMenu>
        </DataGrid.ContextMenu>

        <DataGrid.Columns>
            <DataGridTextColumn Header="Member" Binding="{Binding Name}" CellStyle="{StaticResource LeftAlignedCell}" />
            <DataGridTextColumn Header="Path" Binding="{Binding Path}"/>
            <!--<DataGridTextColumn Header="Address" Width="Auto" Binding="{Binding Address}"/>-->
            <DataGridTextColumn Header="Port" Binding="{Binding Port}" />
            <DataGridTextColumn Header="Connections" Binding="{Binding Statistics.CurrentConnections}" />
            <DataGridTextColumn Header="Status" Binding="{Binding Status}" Width="85" CellStyle="{StaticResource StatusCellStyle}"/>
            <DataGridTextColumn Header="Last Update" Width="*" Binding="{Binding LastUpdate, StringFormat={}\{0:hh:mm:ss tt\}}" CellStyle="{StaticResource LeftAlignedCell}"/>
        </DataGrid.Columns>

    </DataGrid>

</UserControl>
